<?php

namespace App\Console\Commands\OpenShop\Contract;

use App\Models\OpenShop\InvestmentPromotion\OpenShopUserContractModel;
use Illuminate\Console\Command;

class InitUserContractContentCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'contract:init-user-contract-content';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化user_contract.content';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return
     */
    public function handle()
    {
        OpenShopUserContractModel::query()
                                 ->where('content', '!=', null)
                                 ->get()
                                 ->each(function ($item) {

                                     $specialOrderNo = 'KD2023070359125116';

                                     if ($item->orderNo == $specialOrderNo) {

                                         // 特殊
//                                         $config = [
//                                             'rule'      => [
//                                                 [
//                                                     'startPrice' => 0,
//                                                     'endEqPrice' => 990000000,
//                                                     'type'       => 'percent',
//                                                     'percent'    => 0.1,
//                                                 ],
//                                             ],
//                                             'isStop'    => false,
//                                             'isPause'   => false,
//                                             'pauseRule' => [],
//                                             'stopRule'  => [
//                                                 'totalAmount' => 3980000,
//                                             ],
//                                         ];

                                         $item->depositAmountRatio = 0.1;
                                         $item->isCommissionCapping = 1;
                                         $item->amountCommissionCapping = 3980000;

                                     } else {

                                         // 默认12w,3%
//                                         $config = [
//                                             'rule'      => [
//                                                 [
//                                                     'startPrice' => 0,
//                                                     'endEqPrice' => 12000000,
//                                                     'type'       => 'percent',
//                                                     'percent'    => 0.01,
//                                                 ],
//                                             ],
//                                             'isStop'    => false,
//                                             'isPause'   => false,
//                                             'pauseRule' => [],
//                                             'stopRule'  => [],
//                                         ];

                                         $item->depositAmountRatio = 0.03;
                                         $item->monthRealAmountCommissionCapping = 12000000;
                                     }

//                                     $item->content = json_encode($config, true);
                                     $item->save();

                                     $this->info($item->orderNo);
                                 });
    }
}
